package com.pd.backend.common.handler;

import com.pd.backend.common.R;
import com.pd.backend.ex.CustomerException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 */
@RestControllerAdvice
@Slf4j
public class  GlobalExceptionHandler {

    /**
     * 处理CustomerException异常
     * @param ex
     * @return
     */
    @ExceptionHandler(CustomerException.class)
    public R<String> doCustomerException(CustomerException ex){
        log.error("doCustomerException:{}",ex);
        return R.error(ex.getMessage());
    }
/*
    @ExceptionHandler(RuntimeException.class)
    public R<String> doRuntimeException(RuntimeException e){
        log.error("doRuntimeException:{}",e.getMessage());
        return R.error("运行时异常");
    }*/
}